<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <link rel="icon" href="/favicon.ico">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>绑定 HTML Class</title>
  <style>
    .active {
      background-color: cornflowerblue;

    }

    .static.active {
      font-size: 10px;
    }

    .text-danger {
      background-color: crimson;
    }
  </style>
</head>

<body>
  <script src="./src/vue.js"></script>
  <!--对象语法/数组语法-->
  <div id="app">
    <div v-bind:class="{ active: isActive }">class1</div>
    <div class="static" v-bind:class="{ active: isActive }">class2</div>
    <div class="static" v-bind:class="{ active: isActive, 'text-danger': hasError }">class3</div>
    <div v-bind:class="classObject1">classObject1</div>
    <div v-bind:class="classObject2">classObject2</div>
    <div v-bind:class="[activeClass, errorClass]">[activeClass, errorClass]</div>
  </div>
  <script>
    var app = new Vue({
      el: '#app',
      data: {
        isActive: true,
        hasError: true,
        classObject1: {
          active: true,
          'text-danger': false
        },
        error: null,
        activeClass: 'active',
        errorClass: 'text-danger'
      },
      computed: {
        classObject2: function () {
          return {
            active: this.isActive && !this.error,
            'text-danger': this.error && this.error.type === 'fatal'
          }
        }
      }
    })
  </script>

  <!--用在组件上-->
  <!--TODO-->
</body>

</html>